package com.sky.web.admin;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/admin/common")
public class CommonController {

    //阿里云依赖注入
    @Autowired
    private AliOssUtil aliOssUtil;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException { //1 接收参数----MultipartFile
        //2 调用aliyun.oss API 完成文件上传
        String url = aliOssUtil.upload(file.getOriginalFilename(), file.getInputStream());
        log.info("图片上传之后的访问路径是{}",url);

        //3 返回结果(路径)
        return Result.success(url);
    }


}
